<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Services\MakeProductOrder\MakeProductOrder;
use Illuminate\Support\Facades\Redis;
use App\Models\User;


class MakeSeckillOrderJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public int $uid;
    public string $unpaidCacheId;

    public function __construct($uid, $unpaidCacheId)
    {
        $this->uid = $uid;
        $this->unpaidCacheId = $unpaidCacheId;
    }


    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->user = User::find($this->uid);

        $this->items = [
            [
                'sku_id' => Redis::hGet($this->unpaidCacheId, 'product_sku_id'),
                'amount' => 1
             ]
        ];
         $order = app(MakeProductOrder::class, [
            'user' => $this->user,
            'address' => null,
            'items' => $this->items,
            'cacheId' => $this->unpaidCacheId
        ])->make();
    }
}
